package com.bsj.power.pls.web;

import cn.dev33.satoken.annotation.SaIgnore;
import com.bsj.power.common.config.cached.RedisCached;
import com.bsj.power.common.config.global.JsonResult;
import com.bsj.power.common.def.dto.DeleteDTO;
import com.bsj.power.common.def.dto.personnel.PersonnelDTO;
import com.bsj.power.common.def.dto.personnel.PersonnelSearchDTO;
import com.bsj.power.common.def.dto.personnel.WorkPersonnelSearchDTO;
import com.bsj.power.common.def.vo.KeyValueVO;
import com.bsj.power.common.def.vo.pls.PersonnelVO;
import com.bsj.power.common.def.vo.pls.WorkPersonnelVO;
import com.bsj.power.pls.service.PersonnelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import redis.clients.bsj.JedisClusterBSJ;

import java.util.List;
import java.util.Map;

/**
 * @author LiJiaXin
 * @version 1.0.0
 * @description PersonnelController
 * @time 2024/4/18 15:45
 */
@RestController
@RequestMapping("/personnel")
//@SaCheckPermission("/pls/personnel")
public class PersonnelController {

    @Autowired
    private PersonnelService personnelService;

    /**
     * 添加人员信息
     *
     * @param personnelDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/4/18 17:00
     */
    @PostMapping("/add")
    public JsonResult add(@Validated @RequestBody PersonnelDTO personnelDTO) {
        return personnelService.addPersonnel(personnelDTO);
    }

    /**
     * 删除人员信息
     *
     * @param deleteDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/4/18 19:48
     */
    @PostMapping("/delete")
    public JsonResult delete(@RequestBody DeleteDTO deleteDTO) {
        return personnelService.deletePersonnel(deleteDTO);
    }

    /**
     * 修改人员信息
     *
     * @param personnelDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/4/18 17:37
     */
    @PostMapping("/update")
    public JsonResult update(@Validated @RequestBody PersonnelDTO personnelDTO) {
        return personnelService.updatePersonnel(personnelDTO);
    }

    /**
     * 获取单个人员信息
     *
     * @param personnelId
     * @return com.bsj.power.common.config.global.JsonResult<com.bsj.power.common.def.vo.pls.PersonnelVO>
     * @author ljx
     * @time 2024/4/18 19:53
     */
    @GetMapping("/getById/{personnelId}")
    public JsonResult<PersonnelVO> getById(@PathVariable("personnelId") Integer personnelId) {
        return JsonResult.success(personnelService.getPersonnelById(personnelId));
    }

    /**
     * 人员信息分页
     *
     * @param personnelSearchDTO
     * @return com.bsj.power.common.config.global.JsonResult<java.util.List < com.bsj.power.common.def.vo.pls.PersonnelVO>>
     * @author ljx
     * @time 2024/4/18 19:54
     */
    @GetMapping("/page")
    public JsonResult<List<PersonnelVO>> page(@Validated PersonnelSearchDTO personnelSearchDTO) {
        return personnelService.pagePersonnel(personnelSearchDTO);
    }

    /**
     * 分页查询作业人员信息
     *
     * @param dto
     * @return
     */
    @GetMapping("/pageWorkPersonnel")
    public JsonResult<List<WorkPersonnelVO>> pageWorkPersonnel(@Validated WorkPersonnelSearchDTO dto) {
        return personnelService.pageWorkPersonnel(dto);
    }

    /**
     * 根据id获取作业人员信息
     *
     * @param id
     * @return com.bsj.power.common.config.global.JsonResult<com.bsj.power.common.def.vo.pls.WorkPersonnelVO>
     * @author ljx
     * @time 2024/9/12 14:36
     */
    @GetMapping("/getWorkPersonnelById/{id}")
    public JsonResult<WorkPersonnelVO> getWorkPersonnelById(@PathVariable("id") Integer id) {
        return JsonResult.success(personnelService.getWorkPersonnelById(id));
    }

    /**
     * 模糊搜索
     *
     * @param value
     * @param isBind
     * @return com.bsj.power.common.config.global.JsonResult<java.util.List < com.bsj.power.common.def.vo.KeyValueVO>>
     * @author ljx
     * @time 2024/5/10 14:09
     */
    @GetMapping("/fuzzySearch")
    public JsonResult<List<KeyValueVO>> fuzzySearch(String value, Boolean isBind) {
        return JsonResult.success(personnelService.fuzzySearch(value, isBind));
    }

    /**
     * 是否关注
     *
     * @param personType  人员类型 1负责人 2作业人员
     * @param personId    人员id
     * @param isAttention 1关注 2取消关注
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/9/25 19:35
     */
    @GetMapping("/isAttention")
    public JsonResult isAttention(Integer personType, Integer personId, Integer isAttention) {
        return JsonResult.success(personnelService.isAttention(personType, personId, isAttention));
    }

    /**
     * 删除作业人员信息
     *
     * @param deleteDTO
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/11/19 16:23
     */
    @PostMapping("/deleteWorkPersonnel")
    public JsonResult deleteWorkPersonnel(@RequestBody DeleteDTO deleteDTO) {
        return personnelService.deleteWorkPersonnel(deleteDTO);
    }

    /**
     * 获取平台未绑卡的人员编号缓存脏数据
     *
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/7/10 10:17
     */
    @SaIgnore
    @GetMapping("/getPersonNoInfo")
    public JsonResult<Map<String,String>> getPersonNoInfo() {
        return JsonResult.success(personnelService.getPersonNoInfo());
    }

    /**
     * 清除平台未绑卡的人员编号缓存脏数据
     *
     * @return com.bsj.power.common.config.global.JsonResult
     * @author ljx
     * @time 2024/7/10 10:17
     */
    @SaIgnore
    @GetMapping("/cleanPersonNoInfo")
    public JsonResult<Map<String,String>> cleanPersonNoInfo() {
        return JsonResult.success(personnelService.cleanPersonNoInfo());
    }

}
